export const productionVersionHook = () => {
  const event = {
    addEvent: "ADD-PRODUCTION-VERSION",
    copyEvent: "COPY-PRODUCTION-VERSION",
    editEvent: "EDIT-PRODUCTION-VERSION",
    editByTemplateEvent: "EDIT-BY-TEMPLATE-PRODUCTION-VERSION",
    worker: "PRODUCTION-VERSION-WORKER",
    workerSubmit: "PRODUCTION-VERSION-WORKER-SUBMIT",
    equip: "PRODUCTION-VERSION-EQUIP",
    material: "PRODUCTION-VERSION-MATERIAL",
    bomTree: "PRODUCTION-VERSION-MATERIAL-BOM",
    bomTreeSubmit: "PRODUCTION-VERSION-MATERIAL-BOM-SUBMIT",
    supplier: "PRODUCTION-VERSION-SUPPLIER",
    refreshEvent: "TABLE-REFRESH",
  };
  const api = {
    page: "/mes/mesproduceversion/queryByPage",
    save: "/mes/mesproduceversion/save",
    delete: "/delete",
    get: "/mes/mesproduceversion/get",
    deleteItem: "/mes/mesproduceversion/deleteItem",
    stopUsing: "/mes/mesproduceversion/stopUsing",
    copy: "/mes/mesproduceversion/copy",
    getPlantIdList: "/system/sysOrganization/getList",
    getProcessTemplate: "/mes/mesroutingtemplate/getList",
    getBom: "/mes/mesbom/getList",
    getTemplateDetail: "/mes/mesroutingtemplate/getDetails",
    getProcessList: "/mes/mesprocess/getList",
    getEquipmentList: "/mdm/mdmequipinfo/getList",
    getProduceStorageList: "/mes/mesproducestorage/getList",
    getBomTree: "mes/mesbom/getBomTree",
    getBomDetail: "mes/mesbom/getDetails",
  };

  function validateInt(rule: any, value: any) {
    return new Promise((resolve, reject) => {
      validateNumber(rule, value)
        .then(() => {
          if (Number(value) > 2147483647) {
            return reject("最大值2147483647");
          } else {
            return resolve();
          }
        })
        .catch((e) => {
          return reject(e);
        });
    });
  }
  function validateNumber(rule: any, value: any) {
    if (value === "" || value === undefined || value === null)
      return Promise.resolve();
    if (isNaN(parseFloat(value)) && isFinite(value)) {
      return Promise.reject("请输入数字");
    } else if (!/^[+-]?\d*(\.\d*)?(e[+-]?\d+)?$/.test(value)) {
      return Promise.reject("请输入数字");
    } else if (Number(value) <= 0) {
      return Promise.reject("请输入大于0的值");
    } else {
      return Promise.resolve();
    }
  }
  function validateDecimal(rule: any, value: any) {
    return new Promise((resolve, reject) => {
      validateNumber(rule, value)
        .then(() => {
          if (Number(value) > 999_999_999_999_999_999.999999) {
            return reject("最大值999999999999999999.999999");
          } else {
            return resolve();
          }
        })
        .catch((e) => {
          return reject(e);
        });
    });
  }
  return {
    event,
    api,
    validateInt,
    validateDecimal,
  };
};
